#
# @lc app=leetcode.cn id=20 lang=python3
#
# [20] 有效的括号
#

# @lc code=start
class Solution:
    def isValid(self, s: str) -> bool:
        list = []
        dict = {'(':')','[':']','{':'}'}
        for i in s:
            if i in ['(','[','{']:
                list.append(i)
            else:
                if len(list) == 0 or i != dict[list[-1]]:
                    return False
                else:
                    list.pop()
        if len(list) == 0:
            return True
        else:
            return False

# @lc code=end
